package edu.bit.water.controller;

import edu.bit.water.entity.MetaCleanProduct;
import edu.bit.water.entity.NewCleanProduct;
import edu.bit.water.entity.MetaWaterSaving;
import edu.bit.water.service.NewCleanProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/new_clean_product")
public class NewCleanProductController {

    @Autowired
    private NewCleanProductService newCleanProductService;

    /**
     * 查询clean_product中的记录
     * @return clean_product的所有记录
     */
    @RequestMapping("/select")
    @ResponseBody
    public Map<String, Object> select(){
        Map<String, Object> modelMap = new HashMap<>();
        List<NewCleanProduct> list = newCleanProductService.select();
        modelMap.put("status", "success");
        modelMap.put("rows", list);
        return modelMap;
    }

    /**
     * @param newCleanProduct
     * @return 成功返回1,失败返回0
     */
    @RequestMapping("/insert")
    @ResponseBody
    public Map<String, String> insert(NewCleanProduct newCleanProduct){
        return newCleanProductService.insert(newCleanProduct);
    }

    /**
     * 更新记录
     * @param newCleanProduct
     * @return 成功返回1,失败返回0
     */
    @RequestMapping("/update")
    @ResponseBody
    public Map<String, String> update(NewCleanProduct newCleanProduct){
        return newCleanProductService.update(newCleanProduct);
    }

    /**
     * 删除记录
     * @param ids 删除记录的标识符
     * @return 成功返回1,失败返回0
     */
    @RequestMapping("/delete")
    @ResponseBody
    public Map<String, Object> delete(@RequestBody List<Integer> ids){
        Map<String, Object> modelMap = new HashMap<>();
        int n = newCleanProductService.delete(ids);
        if(n == 1) {
            modelMap.put("status", "success");
        }
        else
            modelMap.put("status", "failed");
        return modelMap;
    }

    /**
     * 查询所属行业对应的标准号
     * @return 所属行业对应的所有标准号
     */
    @RequestMapping("/get_eva_basis")
    @ResponseBody
    public Map<String, Object> getEvaBasis(String class2){
        Map<String, Object> modelMap = new HashMap<>();
        List<MetaCleanProduct> list = newCleanProductService.getEvaBasis(class2);
        modelMap.put("status", "success");
        modelMap.put("rows", list);
        return modelMap;
    }

    /**
     * 查询元数据所有标准号的状态
     *
     * @return 元数据所有标准号的状态
     */
    @RequestMapping("/get_standard_status")
    @ResponseBody
    public Map<String, Object> getStandardStatus() {
        Map<String, Object> modelMap = new HashMap<>();
        List<MetaCleanProduct> list = newCleanProductService.getStandardStatus();
        modelMap.put("status", "success");
        modelMap.put("rows", list);
        return modelMap;
    }
}